home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / dfpp01.zip / CURSOR.CPP < prev    next >
C/C++ Source or Header  |  1992-11-21  |  2KB  |  105 lines

  1. // ------------ cursor.cpp
  2.  
  3. #include <dos.h>
  4. #include "cursor.h"
  5. #include "desktop.h"
  6.  
  7. Cursor::Cursor()
  8. {
  9.     cs = 0;
  10.     Save();
  11. }
  12.  
  13. Cursor::~Cursor()
  14. {
  15.     Restore();
  16. }
  17.  
  18. // ------ get cursor shape and position
  19. void Cursor::GetCursor()
  20. {
  21.     regs.h.ah = READCURSOR;
  22.     regs.x.bx = desktop.screen().Page();
  23.     int86(VIDEO, ®s, ®s);
  24. }
  25.  
  26. // -------- get the current cursor position
  27. void Cursor::GetPosition(int &x, int &y)
  28. {
  29.     GetCursor();
  30.     x = regs.h.dl;
  31.     y = regs.h.dh;
  32. }
  33.  
  34. // ------ position the cursor
  35. void Cursor::SetPosition(int x, int y)
  36. {
  37.     regs.x.dx = ((y << 8) & 0xff00) + x;
  38.     regs.h.ah = SETCURSOR;
  39.     regs.x.bx = desktop.screen().Page();
  40.     int86(VIDEO, ®s, ®s);
  41. }
  42.  
  43. // ------ save the current cursor configuration
  44. void Cursor::Save()
  45. {
  46.     if (cs < MAXSAVES)    {
  47.         GetCursor();
  48.         cursorshape[cs] = regs.x.cx;
  49.         cursorpos[cs] = regs.x.dx;
  50.         cs++;
  51.     }
  52. }
  53.  
  54. // ---- restore the saved cursor configuration
  55. void Cursor::Restore()
  56. {
  57.     if (cs)    {
  58.         --cs;
  59.         regs.x.dx = cursorpos[cs];
  60.         regs.h.ah = SETCURSOR;
  61.         regs.x.bx = desktop.screen().Page();
  62.         int86(VIDEO, ®s, ®s);
  63.         SetType(cursorshape[cs]);
  64.     }
  65. }
  66.  
  67. /* ---- set the cursor type ---- */
  68. void Cursor::SetType(unsigned t)
  69. {
  70.     regs.h.ah = SETCURSORTYPE;
  71.     regs.x.bx = desktop.screen().Page();
  72.     regs.x.cx = t;
  73.     int86(VIDEO, ®s, ®s);
  74. }
  75.  
  76. /* ----- swap the cursor stack ------- */
  77. void Cursor::SwapStack()
  78. {
  79.     if (cs > 1)    {
  80.         swap(cursorpos[cs-2], cursorpos[cs-1]);
  81.         swap(cursorshape[cs-2], cursorshape[cs-1]);
  82.     }
  83. }
  84.  
  85. /* ------ hide the cursor ------ */
  86. void Cursor::Hide()
  87. {
  88.     GetCursor();
  89.     regs.h.ch |= HIDECURSOR;
  90.     regs.h.ah = SETCURSORTYPE;
  91.     int86(VIDEO, ®s, ®s);
  92. }
  93.  
  94. /* ------ show the cursor ------ */
  95. void Cursor::Show()
  96. {
  97.     GetCursor();
  98.     regs.h.ch &= ~HIDECURSOR;
  99.     regs.h.ah = SETCURSORTYPE;
  100.     int86(VIDEO, ®s, ®s);
  101. }
  102.  
  103.  
  104.  
  105.